<template>
  <div>
    <f-form ref="form" :action="api.payment" handlerName="cbReturnPaymentSaveHandler" :form-key="this.formItem.paymentId">
      <f-form-item label="退款金额" type="number" name="amount" dataType="number" :value="formItem.amount" :max="formItem.amount" :precision="4" :required="true" :disabled="true"/>
      <f-form-item label="收款人" ref="saleMan" name="saleManId" type="select" :data="api.saleman.list" valueKey="saleManId" :value="formItem.saleManId" :required="true" label-key="saleManName" @change="saleManChange" :auto-load="false"/>
      <f-form-item label="收款账户" ref="bank" type="select" name="bankId" :value="formItem.bankId" :data="api.salemanBank.list" valueKey="bankId" label-key="bankName,bankNo" :required="true" :params="queryParam" :auto-load="false"/>
      <f-form-item label="退款日期" type="date" name="amountDate" :required="true" :value="formItem.amountDate"/>
      <f-form-item label="备注" name="remark" :value="formItem.remark"/>
    </f-form>
  </div>
</template>
<script>
  import api from './../js/api'
  export default {
    name: 'CbreturnForm',
    components: {},
    data() {
      return {
        api: Object.assign(api, this.api),
        //列表初始化查询参数
        queryParam: {
          deptId: ''
        },
        formItem: this.getFormItem()
      }
    },
    created() {
    },
    methods: {
      getFormItem() {
        return {
          orderDetailsId: '',
          deptId: '',
          bankId: null,
          selectIds: '',
          amount: 0,
          amountDate: '',
          remark: ''
        }
      },
      setData(data) {
        if (data && data.deptId) {
          this.formItem.amount = parseFloat(data.customBond)
          this.formItem.deptId = data.deptId
          this.formItem.selectIds = data.selectIds
          this.formItem.orderDetailsId = data.orderDetailsId
          this.$nextTick(() => {
            this.$refs['saleMan'].initData({ deptId: data.deptId })
          })
        }
      },
      //业务员切换
      saleManChange(value) {
        this.$refs.form.getForm().resetFields(['bankId'])
        this.$refs['bank'].initData({ saleManId: value })
      },
      handleSubmit() {
        let params = {
          orderDetailsId: this.formItem.orderDetailsId,
          amount: this.formItem.amount,
          selectIds: this.formItem.selectIds,
          deptId: this.formItem.deptId
        }
        this.$refs['form'].submit(params, this.handleSuccess)
      },
      handleSuccess() {
        this.$emit('closeDrawer', false)
      }
    }
  }
</script>
